﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataAccess;

namespace TimKiemDiaDiem
{
    public partial class MainForm : Form , MainFormUI  
    {
        public MainForm()
        {
            InitializeComponent();

            Db.Initation("", "Database20111015", "", "");
            WorkspaceUI workspace = new frmChonDichVu(this);
            this.Controls.Add(workspace);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        HienThiMapForm mapForm = new HienThiMapForm();
        public HienThiMapForm MapForm
        {
            get { return mapForm; }
            set { mapForm = value; }
        }

        public WorkspaceUI CurrenWorkspace
        {
            get {
                return (WorkspaceUI)this.Controls[this.Controls.Count - 1];
            }
            set {
                this.Controls.RemoveAt(this.Controls.Count - 1);
                this.Controls.Add(value);
                this.ResumeLayout(false);
                this.PerformLayout();
            }
        }
        public void LoadWorkspace(WorkspaceUI workspace)
        {
            this.Controls.RemoveAt(this.Controls.Count - 1);
            this.Controls.Add(workspace);
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        private void ChangeFunction(String FunctionName)
        {
            switch (FunctionName)
            {
                case "TimKiem":
                    pnTimKiem.BackgroundImage = global::TimKiemDiaDiem.Properties.Resources.BlankItem;
                    pnCapNhatDuLieu.BackgroundImage = global::TimKiemDiaDiem.Properties.Resources.ItemChucNang;
                    
                    if(this.CurrenWorkspace.Context == "CapNhatDuLieu")
                        this.LoadWorkspace( new frmChonDichVu(this));
                    break;
                case "CapNhatDuLieu":
                    pnCapNhatDuLieu.BackgroundImage = global::TimKiemDiaDiem.Properties.Resources.BlankItem;
                    pnTimKiem.BackgroundImage = global::TimKiemDiaDiem.Properties.Resources.ItemChucNang;
                    
                    if(this.CurrenWorkspace.Context != "CapNhatDuLieu")
                        this.LoadWorkspace(new frmCapNhatDuLieu(this));
                    break;
            }
        }

        private void pnTimKiem_MouseClick(object sender, MouseEventArgs e)
        {
            this.ChangeFunction("TimKiem");
        }

        private void pnCapNhatDuLieu_MouseClick(object sender, MouseEventArgs e)
        {
            this.ChangeFunction("CapNhatDuLieu");
        }

        private void lblTimKiem_Click(object sender, EventArgs e)
        {
            this.ChangeFunction("TimKiem");
        }

        private void lblCapNhatDuLieu_Click(object sender, EventArgs e)
        {
            this.ChangeFunction("CapNhatDuLieu");
        }

        private void MainForm_Shown(object sender, EventArgs e)
        {
            LoadingForm loadForm = new LoadingForm();
            loadForm.ShowDialog(this); 
        }               
    }
}
